#pragma once
#include <set>
#include <unordered_map>
#include "base/core/singleton.h"
#include "Common/CharacterDefine.h"
#include "ProtoBuffer/AllProtocol.h"
using namespace ProtoBuf;

class CharacterDataSet : public ManualSingleton<CharacterDataSet>
{
	friend class ManualSingleton<CharacterDataSet>;

private:
	typedef std::unordered_map<CharIDType, std::set<CharIDType>> CHARACTER_IDS_MAP;
	typedef std::unordered_map<CharIDType, CharacterDBInfo*> CHARACTER_MAP;

	CHARACTER_IDS_MAP m_charIdsMap;
	CHARACTER_MAP   m_charMap;

public:
    bool Init();
    bool UnInit();

public:
	bool AddCharacterData(const std::string& channelId, const std::string& userId, const CharacterDBInfo& charInfo);
	bool DelCharacterData(const std::string& channelId, const std::string& userId, CharIDType charId);

    bool ClearCharacterData(const std::string& channelId, const std::string& userId);
	bool CheckHaveCharacter(const std::string& channelId, const std::string& userId, CharIDType charId);

	CharacterDBInfo* GetCharacterData(CharIDType charId);
    uint32_t GetCharacterCount(const std::string& channelId, const std::string& userId);

	bool GetCharacterSimpleInfoList(const std::string& channelId, const std::string& userId, ClientCharacterListResponse& charSimpleInfoList);
	bool GetCharacterSimpleInfo(CharIDType charId, CharacterDBSimpleInfo& charSimpleInfo);

protected:
    uint64_t _GetKey(const std::string& channelId, const std::string& userId);

protected:
	CharacterDataSet();
	~CharacterDataSet();
};

#define  g_MakeCharacterDataSet()    (CharacterDataSet::Instance())
#define  g_GetCharacterDataSet()     (CharacterDataSet::GetInstance())
#define  g_DelCharacterDataSet()     (CharacterDataSet::Destroy())
